package com.enqualcomm.kids.component;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.enqualcomm.kids.config.userdefault.AppDefault;
import com.igexin.sdk.PushConsts;

import common.utils.MyLogger;

/**
 * Created by yinzhiqun on 2015/9/23.
 *
 */
public class GetuiReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        switch (bundle.getInt(PushConsts.CMD_ACTION)) {
            case PushConsts.GET_MSG_DATA:
                // 获取透传数据
                MyLogger.jLog().i("收到透传消息");
//                byte[] payload = bundle.getByteArray("payload");
//                if (payload != null){
//                    String data = new String(payload);
//                    MyLogger.jLog().i(data);
//                }

                Intent intent1 = new Intent(context, CmdIntentService.class);
                intent1.setAction(CmdIntentService.GET_PUSH_DATA);
                context.startService(intent1);
                break;
            case PushConsts.GET_CLIENTID:
                // 第三方应用需要将CID上传到第三方服务器，并且将当前用户帐号和CID进行关联，以便日后通过用户帐号查找CID进行消息推送

                String clientid = bundle.getString("clientid");
                if (clientid!=null) {
                    MyLogger.jLog().i("获取cid成功");
                    AppDefault appDefault = new AppDefault();
                    appDefault.setPushClientId(clientid);
                    Intent service = new Intent(context, CmdIntentService.class);
                    service.setAction(CmdIntentService.REGISTER_PUSH_SERVICE);
                    context.startService(service);
                }

                break;
        }
    }
}
